﻿Imports System.Data.SqlClient
Public Class clsDieselSinRecorrido
    Private mintIdDiesel As Integer
    Private mdatFecha As Date
    Private mintIdAutobus As Integer
    Private mstrNoEconomico As String
    Private mdblLitros As Double
    Private mstrCodigoOperador As String
    Private mstrNombreOperador As String
    Private mstrCodigoDespachador As String
    Private mstrNombreDespachador As String
    Public Property IdDiesel() As Integer
        Get
            Return mintIdDiesel
        End Get
        Set(ByVal value As Integer)
            mintIdDiesel = value
        End Set
    End Property
    Public Property Fecha As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property
    Public Property NoEconomico() As String
        Get
            Return mstrNoEconomico
        End Get
        Set(ByVal value As String)
            mstrNoEconomico = value
        End Set
    End Property
    Public Property Litros() As Double
        Get
            Return mdblLitros
        End Get
        Set(ByVal value As Double)
            mdblLitros = value
        End Set
    End Property
    Public Property CodigoOperador() As String
        Get
            Return mstrCodigoOperador
        End Get
        Set(ByVal value As String)
            mstrCodigoOperador = value
        End Set
    End Property
    Public Property NombreOperador() As String
        Get
            Return mstrNombreOperador
        End Get
        Set(ByVal value As String)
            mstrNombreOperador = value
        End Set
    End Property
    Public Property CodigoDespachador() As String
        Get
            Return mstrCodigoDespachador
        End Get
        Set(ByVal value As String)
            mstrCodigoDespachador = value
        End Set
    End Property
    Public Property NombreDespachador() As String
        Get
            Return mstrNombreDespachador
        End Get
        Set(ByVal value As String)
            mstrNombreDespachador = value
        End Set
    End Property
    Public Sub New()
        mintIdDiesel = 0
        mdatFecha = Now()
        mintIdAutobus = 0
        mstrNoEconomico = ""
        mdblLitros = 0
        mstrCodigoOperador = ""
        mstrNombreOperador = ""
        mstrCodigoDespachador = ""
        mstrNombreDespachador = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Diesel (" & _
                            "Fecha," & _
                            "IdAutobus," & _
                            "NoEconomico," & _
                            "Litros," & _
                            "CodigoOperador," & _
                            "NombreOperador," & _
                            "CodigoDespachador," & _
                            "NombreDespachador)" & _
                            "VALUES (" & _
                            "@Fecha," & _
                            "@IdAutobus," & _
                            "substring(@NoEconomico,1,50)," & _
                            "@Litros," & _
                            "substring(@CodigoOperador,1,50)," & _
                            "substring(@NombreOperador,1,150)," & _
                            "substring(@CodigoDespachador,1,50)," & _
                            "substring(@NombreDespachador,1,150))"
                            
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("Litros", mdblLitros)
        Command.Parameters.AddWithValue("CodigoOperador", mstrCodigoOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("CodigoDespachador", mstrCodigoDespachador)
        Command.Parameters.AddWithValue("NombreDespachador", mstrCodigoDespachador)
        
        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Liquidacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()

        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = CitraConnection
        strSqlQry = "Update Diesel Set " & _
                    "Fecha=@Fecha," & _
                    "IdAutobus=@IdAutobus," & _
                    "NoEconomico=substring(@NoEconomico,1,50)," & _
                    "Litros=@Litros," & _
                    "CodigoOperador=substring(@CodigoOperador,1,50)," & _
                    "NombreOperador=substring(@NombreOperador,1,150)," & _
                    "CodigoDespachador=substring(@CodigoDespachador,1,50)," & _
                    "NombreDespachador=substring(@NombreDespachador,1,150) " & _
                    "Where IdDiesel=@IdDiesel"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdDiesel", mintIdDiesel)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("Litros", mdblLitros)
        Command.Parameters.AddWithValue("CodigoOperador", mstrCodigoOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("CodigoDespachador", mstrCodigoDespachador)
        Command.Parameters.AddWithValue("NombreDespachador", mstrCodigoDespachador)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
End Class
